package com.chixing.controller;

import com.chixing.entity.MongDB.Reply;
import com.chixing.service.impl.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/replies")
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    /**
     * 新增回复
     */
    @PostMapping
    public Reply addReply(@RequestBody Reply reply) {
        return replyService.addReply(reply);
    }

    /**
     * 获取某主楼的平铺回复列表
     */
    @GetMapping("/post/{postId}")
    public List<Reply> getRepliesByPost(@PathVariable String postId) {
        return replyService.getRepliesByPostId(postId);
    }

    /**
     * 获取某主楼的树形楼中楼
     */
    @GetMapping("/post/{postId}/tree")
    public List<Reply> getReplyTree(@PathVariable String postId) {
        return replyService.getReplyTreeByPostId(postId);
    }

    /**
     * 查询用户所有回复
     */
    @GetMapping("/user/{userId}")
    public List<Reply> getRepliesByUser(@PathVariable Long userId) {
        return replyService.getRepliesByUser(userId);
    }
}
